<?php

namespace User;

use C\L\AdmController;
use C\M\Payment;

class LevelController extends AdmController
{
    protected function init()
    {
        $this->service = $this->s_level;
        $this->hideKeys = [
        'is_delete'
        ];

        $this->timeToDateKeys = [
        'addtime', 'uptime'
        ];

        $this->updateKeys = [
        'name', 'credit', 'apr', 'payment_id',
        ];

        $this->createKeys = [
        'name', 'credit', 'apr', 'payment_id',
        ];
    }

    protected function beforeSearch()
    {
        $this->params['order'] = 'credit asc';
        return true;
    }

    protected function afterSearch(&$data)
    {
        foreach ($data['list'] as &$item) {
            $payment = Payment::findById($item['payment_id']);
            $item['payment_name'] = $payment->name ?? null;
        }

        return true;
    }
}
